﻿Imports System.Collections.Specialized
Imports System.Windows.Forms

Public Class Balance3Add

#Region "插入模式"

    Public Overrides Function DoAddCheck() As Boolean
        DoAddCheck = False

        DoAddCheck = True
    End Function

    Public Overrides Function DoAddExist() As Boolean
        Return True
    End Function

    Public Overrides Function DoInsert() As Boolean
        MyBase.DoInsert()

        DoInsert = False
        CrashStatus_Backup.CrashStatus_BackUp_手动(ct, dt1.Value.ToString("yyyy-MM-dd"))
        ShowMessageBox("插入成功")
        DoInsert = True
        bAdd = True
        Me.Close()
    End Function

#End Region

#Region "清除窗体"
    Public Sub ClearForm()
    End Sub
#End Region

#Region "加载事件"

    Public Overrides Sub InitAdd()
        ClearForm()
    End Sub

    Private Sub InputAdd_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim sql As String = "select ID,TITLE as 名称,Count as 金额,MEMO AS 备注 from CrashStatus order by 名称"

        dg.DataSource = ct.FillTable(sql)

        dg.Columns("id").Visible = False

        Dim width As Integer = dg.Columns.GetColumnsWidth(DataGridViewElementStates.Visible)
        Me.Width = dg.Left + width + 4 + 11
        If dg.DisplayedRowCount(True) <> dg.RowCount Then
            Me.Width += 20
        End If
    End Sub
#End Region

#Region "更新模式"

    Public Overrides Function DoUpdate() As Boolean
        MyBase.DoUpdate()
        DoUpdate = False

        'CrashStatus_Backup.CrashStatus_BackUp_手动(ct, dt1.Value.ToString("yyyy-MM-dd"))

        For index As Integer = 0 To dg.Rows.Count - 1

            Dim sbInsert As New StringBuilder
            sbInsert.AppendLine(" Insert into CrashStatusBackup(日期,帐户ID,金额,生成状态) Values(")
            sbInsert.AppendLine("'" & dt1.Value.ToString("yyyy-MM-dd") & "','" & dg.Rows(index).Cells("ID").Value & "','" & dg.Rows(index).Cells("金额").Value & "',1")
            sbInsert.AppendLine(")")

            ct.ExecuteSql(sbInsert.ToString)
        Next

        ShowMessageBox("更新成功")
        DoUpdate = True
    End Function

    Public Overrides Function DoUpdateCheck() As Boolean
        MyBase.DoUpdateCheck()
        DoUpdateCheck = True
    End Function

    Public Overrides Function DoUpdateExist() As Boolean
        DoUpdateExist = False
        MyBase.DoUpdateExist()
        If CStr(Me.参数列表("ID")).Trim = "" Then
            ShowMessageBox("没有选择任何记录")
            Exit Function
        End If
        DoUpdateExist = True
    End Function

    Public Overrides Sub InitUpdate()
        MyBase.InitUpdate()
        Me.Text = "收入更新"
        ClearForm()
        Dim rs As ADODB.Recordset = Nothing
        Dim sb As New StringBuilder

        sb.AppendLine(" select WysInput.*,WysInputUser.UserName as UserName1")
        sb.AppendLine("  from WysInput ")
        sb.AppendLine("left join WysInputUser on WysInputUser.id =WysInput.username  WHERE WysInput.id='" + CStr(Me.参数列表("ID")) + "'")

        rs = ct.GetTable(sb.ToString)

        rs.Close()
        System.Runtime.InteropServices.Marshal.ReleaseComObject(rs)

        rs = Nothing
    End Sub

#End Region



End Class